﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace CPPEI.Coolzon.Designer.Views
{
    public static class PasteCommand
    {
        public static void Executed(object sender, ExecutedRoutedEventArgs e)
        {
            PastePartOperation operation = new PastePartOperation(UIContext.Current.CurrentDesignView, UIContext.Current.CurrentDesignView.ToPastePart, (Coolzon.UI.IPartContainer)UIContext.Current.CurrentDesignView.API_GetSelectedPart());
            OperationCenter.Instance.Do(operation);
        }
        public static void CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            if (UIContext.Current.CurrentDesignView != null && UIContext.Current.CurrentDesignView.API_IsEditable() && UIContext.Current.CurrentDesignView.API_HadCopiedOrCuted())
            {
                Coolzon.UI.Part part = UIContext.Current.CurrentDesignView.API_GetSelectedPart();
                if(part is Coolzon.UI.IPartContainer)
                {
                    //在场景中不允许添加非区域控件
                    if(part is Coolzon.UI.ScenePart && !(UIContext.Current.CurrentDesignView.ToPastePart is Coolzon.UI.AreaPart))
                    {
                        e.CanExecute = false;
                    }
                    else
                    {
                        e.CanExecute = true;
                    }
                }
                else
                {
                    e.CanExecute = false;
                }
            }
            else
            {
                e.CanExecute = false;
            }
        }
    }
}
